package com.lovegu.object.middle;

/**
 * @author 老顾
 * @title: Test1
 * @projectName java-restudy
 * @email: 1437594522@qq.com
 * @date 2022/9/21 9:07
 */
public class Test {
    public void method(Person e) { // 设Person类中没有getschool() 方法
        // System.out.pritnln(e.getschool()); //非法,编译时错误
        if (e instanceof Student) {
            Student me = (Student) e; // 将e强制转换为Student类型
            System.out.println(me.getSchool());
        }
    }
    public static void main(String[] args){
        Test t = new Test();
        Student m = new Student();
        t.method(m);
    }
}
